package home.fragment.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.xfengshopping.R;

public class GridViewAdapter extends BaseAdapter {
    private Context mContext;
    private int[] iconIds = {
            R.drawable.ic_supermarket,
            R.drawable.ic_clothing,
            R.drawable.ic_global_buy,
            R.drawable.ic_fresh,
            R.drawable.ic_delivery,
            R.drawable.ic_recharge,
            R.drawable.ic_group_buy,
            R.drawable.ic_coupon,
            R.drawable.ic_save_money,
            R.drawable.ic_all
    };
    // 图标对应的文字数组
    private String[] iconTexts = {
            "新蜂超市",
            "新蜂服饰",
            "全球购",
            "新蜂生鲜",
            "新蜂到家",
            "充值缴费",
            "9.9元拼",
            "领券",
            "省钱",
            "全部"
    };

    public GridViewAdapter(Context context) {
        mContext = context;
    }

    @Override
    public int getCount() {
        return iconIds.length;
    }

    @Override
    public Object getItem(int position) {
        return iconIds[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        if (convertView == null) {
            view = LayoutInflater.from(mContext).inflate(R.layout.grid_view_item, parent, false);
        } else {
            view = convertView;
        }

        ImageView imageView = view.findViewById(R.id.icon_image_view);
        TextView textView = view.findViewById(R.id.icon_text_view);

        imageView.setImageResource(iconIds[position]);
        textView.setText(iconTexts[position]);

        return view;
    }
}
